package service.impl;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import dao.Comment_dao;
import dao.Product_dao;
import dto.CommentDto;
import entity.Comment;
import entity.Product;
import service.Comment_service;

@Service
public class Comment_service_impl implements Comment_service {

	@Autowired
	private Comment_dao comment_dao;
	@Autowired
	private Product_dao product_dao;
	
	@Override
	public boolean save_comment(Comment comment) {
		// TODO Auto-generated method stub
		return comment_dao.save_comment(comment);
	}

	@Override
	public boolean remove_comment(Integer id) {
		// TODO Auto-generated method stub
		return comment_dao.remove_comment(id);
	}

	@Override
	public boolean update_comment(Comment comment) {
		// TODO Auto-generated method stub
		return comment_dao.update_comment(comment);
	}

	@Override
	public Comment getCommentById(Integer id) {
		// TODO Auto-generated method stub
		return comment_dao.getCommentById(id);
	}

	@Override
	public List<Comment> CommentList(Integer productId,Integer type) {
		// TODO Auto-generated method stub
		return comment_dao.CommentList(productId,type);
	}

	@Override
	public CommentDto getCommentDtoById(Integer id) {
		Comment comment=comment_dao.getCommentById(id);
		Product product =product_dao.getproByid(comment.getProductId());
		CommentDto commentDto=new CommentDto();
		BeanUtils.copyProperties(comment, commentDto);
		commentDto.setProductName(product.getProName());
		commentDto.setMainImage(product.getMainImage());
		
		return commentDto;
	}

}
